﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using BLToolkit.DataAccess;
using BLToolkit.Common;
using BLToolkit.Data.Linq;
using BLToolkit.Mapping;

namespace Core
{
    [TableName("tblNgachCongChuc")]
    public class NgachCongChuc
    {
        [PrimaryKey, Identity]
        [MapField("MaNgach")]
        public int ID { get; set; }
        public string TenNgach { get; set; }
        public int Bac { get; set; }
        public float HeSo { get; set; }
        public static IQueryable<NgachCongChuc> NgachCongChucs
        {
            get
            {
                using (var db = new DataContext())
                {
                    return db.GetTable<NgachCongChuc>();
                }
            }
        }
        public static List<NgachCongChuc> All()
        {
            return NgachCongChucs.ToList();
        }
        public static NgachCongChuc Single(int id)
        {
            return NgachCongChucs.SingleOrDefault(x => x.ID == id);
        }
        public static int Add(NgachCongChuc entity)
        {
            using (var db = new DataContext())
            {
                object rs = db.InsertWithIdentity(entity);
                return int.Parse(rs.ToString());
            }
        }
        public static int Update(NgachCongChuc entity)
        {
            using (var db = new DataContext())
            {
                return db.Update(entity);
            }
        }
        public static int Delete(int id)
        {
            return NgachCongChucs.Delete(x => x.ID == id);
        }
    }
}
